package body Pieces is

    function Get_Dimension (P : Piece) return Dimension is
    begin
        return P.Taille;
    end Get_Dimension;

    function Get_Categorie (P : Piece) return Categories.Ptr_Categorie is
    begin
        return P.Cat;
    end Get_Categorie;

	function Get_Id_Comm (P : Piece) return Natural is
	begin
		return P.Id_Comm;
	end Get_Id_Comm;

	function Get_Emplacement (P : Piece) return Emplacements.Emplacement is
	begin
		return P.Empl;
	end Get_Emplacement;
	
	procedure Set_Emplacement (P : in out Piece; E : in Emplacements.Emplacement) is
	begin
		P.Empl := E;
	end Set_Emplacement;

    function Creer (Cat : Categorie_Verre; Taille : Dimension; Id_Comm : Natural) return Ptr_Piece is
    begin
        return new Piece'(Cat => Liste_Categories.Get_Categorie(Cat), Taille => Taille, Empl => Emplacements.Creer(0, Dim(0,0)), Id_Comm => Id_Comm);
    end Creer;

    function Creer (P : Piece) return Ptr_Piece is
        Ret : Ptr_Piece;
    begin
        Ret := new Piece;
        Ret.all := P;
        return Ret;
    end Creer;

    function Surface (P : Piece) return Natural is
    begin
        return Surface(P.Taille);
    end Surface;

	function ToStringPtr (P : Ptr_Piece) return String is
	begin
		if (P /= Null) then
			return ToString(P.all);
		else
			return "invalide";
		end if;
	end ToStringPtr;

	function ToString (P : Piece) return String is
	begin
		return "Catégorie de verre : " & Categories.Get_Categorie_Verre(P.Cat) & ASCII.LF & "Taille : " & 
			ToString(P.Taille) & ASCII.LF & "Emplacement : " & ASCII.LF & ASCII.HT & Emplacements.ToString(P.Empl);
	end ToString;

end Pieces;